#!/usr/bin/env python
# encoding: utf-8
# waf script for builduing project
# author: Anton Feldmann 
# Copyright 2014 anton.feldmann@gmail.com
# license: MIT

import os, sys
from waflib import Build, TaskGen

name = 'robos'

major  = 0
minor  = 1
bugfix = 0

name_version = '%s-%d.%d.%d' % (name, major, minor, bugfix)

application = name
version     = '%d.%d.%d' % (major, minor, bugfix)

top = '.'
out = 'build'

def options(opt):
    opt.load('compiler_cxx')

    #Add configuration options in python
    daiopt = opt.add_option_group ("%s Options" % name.upper())

    daiopt.add_option('--shared',
                      action='store_true',
                      default=False,
                      help='build all libs as shared libs')
    daiopt.add_option('--doubleprecision',
                      action='store_true',
                      default=True,
                      help='double precision is default')
    daiopt.add_option('--assertion',
                      action='store_true',
                      default=True,
                      help ='assertion')
    daiopt.add_option('--daihash',
                      action='store_true',
                      default=False,
                      help ='using hash table')

#Add configuration options in python
    daidebopt = opt.add_option_group ("%s_Debugging Options" % name.upper())

    daidebopt.add_option('--debug',
                      action='store_true',
                      default=False,
                      help='compile the project in debug mode')


def configure(conf):
    env=conf.env
    opt=conf.options

    if not os.name == 'nt':
        env.CXX = 'clang++'

    conf.load('compiler_cxx')

    from waflib import Options
    conf.define('__BIG_ENDIAN__', 0 if sys.byteorder == 'little' else 1)
    conf.define('__ASSERTION__',int(Options.options.assertion))
    conf.define('__WINDOWS__', int(os.name == 'nt'))
    conf.define('__DEBUG__', int(Options.options.debug))

    conf.write_config_header('include/%s_config.hpp' % name, top=True)

    conf.defines={}
    conf.define('__ROBOS_VERSION__', version)
    conf.write_config_header('include/%s_version.hpp' % name, top=True)

def build(bld):
    bld.recurse('src/reflection')
    bld.recurse('src/safety')
    bld.recurse('src/robos')

    from waflib import Options
# process robos.pc.in -> robos.pc - by default it use the task "env" attribute
    pcf = bld(
        features = 'subst',
        source = '%s.pc.in' % name,
        target = '%s.pc' % name,
        install_path = '${PREFIX}/lib/pkgconfig/'
        )

    pcf.env.table.update(
        {'LIBS':'-l%s -l%s -l%s'  % ('robos','reflection','safety'), 
         'VERSION': version,
         'NAME': name,
         'PREFIX': '%s' % Options.options.prefix,
         'INCLUDEDIR': 'include/%s' % name}
        )

